from january_scripts import ict4growth

__author__ = 'pstalidis'
import MySQLdb, json
from collections import Counter


connection = MySQLdb.connect(host="mysql.stalidis.com", user="ict4growth", passwd="stanford", db="ict4growth")
reader = connection.cursor()

reader.execute("""SELECT `UserID`, `Vector` FROM `Users` WHERE NOT `Vector` = "" LIMIT 0,30""")

Users = []
for (UID, Vector) in reader:
    Users.append((UID, Counter(json.loads(Vector))))

Clusters = ict4growth.create_clusters(Users)    # , 0.78

for cluster in Clusters:
    print cluster, Clusters[cluster]["items"], Clusters[cluster]["vector"]
